package com.common.UITags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
/**
 * 表单
 * @author zhanglong
 *
 */
public class FormTableTag extends TagSupport{
	private static final long serialVersionUID = 1L;
	
	
	private String id;
	private String name;
	private String formlabel;
	
	private StringBuffer sBF = new StringBuffer();
	JspWriter out;
	
	
	
	
	
	@Override
	public int doStartTag() throws JspException {
		try{
			out = pageContext.getOut();
			sBF.setLength(0);
			sBF.append("<div style=\"height:5px;\"></div>");//增加一个间隙
			sBF.append("<div class=\"easyui-panel\" ");
			if(!(formlabel==null||"".equals(formlabel))){
				sBF.append(" title=\""+formlabel+"\" ");
				sBF.append(" noheader=false ");
			}else{
				sBF.append(" noheader=true ");
			}
			sBF.append(">");
			sBF.append("<br/>");
			sBF.append(" <form method=\"post\" ");
			sBF.append(" style=\"width: 100%;");
			sBF.append("margin-bottom: 5px;");//需要覆盖easyui的样式，默认的是12px
			sBF.append("\"");
			if(!(id==null||"".equals(id))){
				sBF.append(" id=\"" +id+"\" ");
			}
			if(!(name==null||"".equals(name))){
				sBF.append(" name=\"" +name+"\" ");
			}
			sBF.append(">");
			//表格居中对齐，table和父元素一样大
			sBF.append("<table width=\"99%\" style=\"text-align: center;\">");
			sBF.append("<tr>");
			out.print(sBF.toString());
		}catch(IOException e){
			throw new JspException("标签dropdown往前台写入时异常！");
		}catch(Exception e){
			throw new JspException("标签内部异常！");
		}
		return EVAL_BODY_INCLUDE;
	}
	
	
	@Override
	public int doEndTag() throws JspException {
		try{
			sBF.setLength(0);
			sBF.append("</tr>");
			sBF.append("</table>");
			sBF.append(" </form> ");
			sBF.append(" </div> ");
			out.print(sBF.toString());
		}catch(IOException e){
			throw new JspException("标签dropdown往前台写入时异常！");
		}catch(Exception e){
			throw new JspException("标签内部异常！");
		}
		return EVAL_PAGE;
	}


	//get and set 方法
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getFormlabel() {
		return formlabel;
	}


	public void setFormlabel(String formlabel) {
		this.formlabel = formlabel;
	}

	
}
